package exercises.Charpter8;

import java.util.Random;

import polymorphism.music.Note;

class RandomShapeGenerator2{
	private Random rand = new Random(47);
	public Instrument next(){
		switch (rand.nextInt(5)){
		default:
		case 0: return new Wind();
		case 1: return new Percussion();
		case 2: return new Stringed();
		case 3: return new Brass();
		case 4: return new Woodwind();
		}
	}
}

public class Eight {
	private static RandomShapeGenerator2 gen = new RandomShapeGenerator2();
	public static void tune(Instrument i) {
	    // ...
	    i.play(Note.MIDDLE_C);
	  }
	  public static void tuneAll(Instrument[] e) {
	    for(Instrument i : e)
	      tune(i);
	  }	
	  public static void main(String[] args) {
		    // Upcasting during addition to the array:
		    Instrument[] orchestra = new Instrument[20];
		    for (int i = 0; i < 20; i++){
				orchestra[i] = gen.next();
			}
		    tuneAll(orchestra);
		  }
}
